//
//  HRZShowGoodsSimpleInfoCell.m
//  EMarket
//
//  Created by 石头 on 2018/5/13.
//  Copyright © 2018年 好日子. All rights reserved.
//

#import "HRZShowGoodsSimpleInfoCell.h"

#import "HRZGoodsClassifyDetailModel.h"

#import <UIImageView+WebCache.h>
#import "UIView+SPExtension.h"

#import "HRZGoodsModel.h"

@interface HRZShowGoodsSimpleInfoCell()

@property (strong, nonatomic) UIImageView *goodsImageView;
@property (strong, nonatomic) UILabel *goodsTitleLabel;
@property (strong, nonatomic) UILabel *goodsPriceLabel;

@end

@implementation HRZShowGoodsSimpleInfoCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.goodsImageView];
        [self addSubview:self.goodsTitleLabel];
        [self addSubview:self.goodsPriceLabel];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.width.mas_equalTo(self).multipliedBy(0.8);
        make.height.mas_equalTo(self).multipliedBy(0.8);
        make.top.mas_equalTo(self).offset(10);
    }];
    
    [self.goodsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.goodsImageView.mas_bottom).offset(10);
    }];
    
    [self.goodsPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.goodsTitleLabel.mas_bottom).offset(10);
    }];
    
    
}

- (void)setModel:(HRZGoodsClassifyDetailModel *)model {
    _model = model;
    if ([model isKindOfClass:[HRZGoodsModel class]]) {
        HRZGoodsModel *goodsModel = (HRZGoodsModel *)model;
        
        [_goodsImageView sd_setImageWithURL:URLString(goodsModel.imageURL) placeholderImage:PLACEHOLDERIMAGE];
        _goodsPriceLabel.text = goodsModel.realPrice ? goodsModel.realPrice : @"?/?";
    } else {
        [_goodsImageView sd_setImageWithURL:URLString(_model.goodsImg) placeholderImage:PLACEHOLDERIMAGE];
        _goodsPriceLabel.text = _model.price ? _model.price : @"?/?";
    }
    _goodsTitleLabel.text = _model.goodsName;
}

#pragma mark - ----  Setter  ----
- (UIImageView *)goodsImageView{
    if (!_goodsImageView) {
        _goodsImageView = [[UIImageView alloc] init];
        _goodsImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _goodsImageView;
}

- (UILabel *)goodsTitleLabel{
    if (!_goodsTitleLabel) {
        _goodsTitleLabel = [[UILabel alloc] init];
        _goodsTitleLabel.font = PFR14Font;
    }
    return _goodsTitleLabel;
}

- (UILabel *)goodsPriceLabel{
    if (!_goodsPriceLabel) {
        _goodsPriceLabel = [[UILabel alloc] init];
        _goodsPriceLabel.font = PFR12Font;
        _goodsPriceLabel.textColor = UIColor.redColor;
    }
    return _goodsPriceLabel;
}

@end
